package com.wenwei.sharebox.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.bean.DeviceGoodsBean;
import com.wenwei.sharebox.bean.SupplyGoodsBean;
import com.wenwei.sharebox.net.ApiManager;
import com.wenwei.sharebox.net.BaseSubscriber;

import org.json.JSONObject;

/**
 * Created by Administrator on 2017/8/28.
 */
public class OptionDialog extends Dialog {

    private TextView mOkTv;
    private TextView mCancelTv;
    private Context mContext;
    public OptionDialog(Context context) {
        super(context);
        mContext = context;
    }

    private int shopId;
    private int devicesId;


    public void setMsg(int sId,int deId){
        this.shopId = sId;
        this.devicesId = deId;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_option_dialog);
        setCanceledOnTouchOutside(false);
        initView();
        initEvent();
    }

    private void initView() {
        mOkTv = (TextView) findViewById(R.id.del_dialog_ok);
        mCancelTv = (TextView) findViewById(R.id.del_dialog_cancel);
    }

    private void initEvent() {
        mOkTv .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                supplyGoods();
            }
        });

        mCancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               dismiss();
            }
        });
    }

    private BaseSubscriber<SupplyGoodsBean> supplySubscriber;
    private void supplyGoods(){
        supplySubscriber = new BaseSubscriber<SupplyGoodsBean>(mContext) {
            @Override
            public void onSuccess(SupplyGoodsBean deviceGoodsBean) {
                Toast.makeText(mContext,"补货成功",Toast.LENGTH_SHORT).show();
                dismiss();
            }
        };
        try{
            JSONObject jb = new JSONObject();
            jb.put("shopId",shopId);
            jb.put("deviceSmallId",devicesId);
            ApiManager.getInstance().supplyGoods(supplySubscriber,shopId,devicesId);
        }catch (Exception e){}
    }
}
